<template>
	<view class="bg-light">
		<scroll-view scroll-y="true" class="w-100" :style="'height:calc(100vh - 110rpx) '">
			<view class="py-2 bg-white">
				<view class="mx-2">
					<view class="mt-2">
						<view class="flex">
							<view class="flex-shrink rounded overflow-hidden shadow" style="width: 180rpx; height: 180rpx;">
								<image :src="BASE_IMG+form.Picture_URL" style="width: 100%;height: 100%;" mode=""></image>
							</view>
							<view class="ml-2 flex flex-column justify-between w-100">
								<text class="font font-weight-bold text-ellipsis-2">{{form.Article_Name}}</text>
								<view class="flex justify-between">
									<text class="font-sm text-muted">{{form.Specifications_Name}}</text>
								</view>
								<view class="flex justify-between">
									<money :money="form.Sales_Unit_Price"></money>
									<text class="font">×{{form.Quantity}}</text> 
								</view>
							</view>
						</view>
					</view>
					<!-- 订单信息 -->
					<view class="flex justify-between my-2">
						<text class="font font-weight-bold">订单编号:</text>
						<text class="font text-muted text-ellipsis-1" style="width: 400rpx;">{{form.Sales_Order_SerialNumber}}</text>
					</view>
					<uni-collapse>
						<uni-collapse-item titleBorder="none" border="none" title="实付款" :showArrow="false">
							<template v-slot:title>
								<view class="flex justify-between align-center">
									<view>
										<text class="font font-weight-bold">实付款</text>
										<uni-icons color="#bbb" size="14" type="bottom"></uni-icons>
									</view>
									<money color="#000" :money="form.Reality_Amount"></money>
								</view>
							</template>
							<view class="flex justify-between align-center mt-2">
								<text class="font font-weight-bold">商品总价:</text>
								<money color="#000" :money="accMul(form.Quantity,form.Sales_Unit_Price)"></money>
							</view>
							<view class="flex justify-between align-center my-2">
								<text class="font font-weight-bold">积分抵扣:</text>
								<money color="#dc3545" before="减" :money="accSub(accMul(form.Quantity,form.Sales_Unit_Price),accMul(form.Reality_Amount,form.Quantity))"></money>
							</view>
							<view class="flex justify-between align-center mb-2">
								<text class="font font-weight-bold">积分消费:</text>
								<text class="font text-success">{{form.Sales_Point}}</text>
							</view>
						</uni-collapse-item>
					</uni-collapse>
					<view class="flex justify-between my-2">
						<text class="font font-weight-bold">退款状态:</text>
						<text class="font">{{Row_Status(form.Row_Status)}}</text>
					</view>
					<view class="flex justify-between my-2" v-if="form.Row_Status.charAt(1) == '2'">
						<text class="font font-weight-bold flex-shrink mr-4">拒绝原因:</text>
						<text class="font">{{form.Cause}}</text>
					</view>
					<view class="flex justify-between my-2">
						<text class="font font-weight-bold">退款类型:</text>
						<text class="font">{{form.Row_Status.charAt(0)=='0'?'仅退款':'退货退款'}}</text>
					</view>
					<view class="flex justify-between my-2">
						<text class="font font-weight-bold">申请时间:</text>
						<text class="font">{{form.Submit_Date}}</text>
					</view>
				</view>
			</view>
		</scroll-view>
		<view class="fixed-bottom shadow flex align-center justify-between bg-white" style="height: 110rpx;">
			<!-- <view  @click="handlesubmit('logistics')" class="mx-3 bg-muted px-3 py-2 rounded-circle flex justify-center">
				<text class="text-white font"></text>
			</view> -->
			<view v-if="form.Row_Status.charAt(1)=='3'" @click="handlesubmit('logistics')" class="mx-3 bg-muted px-3 py-2 rounded-circle flex justify-center">
				<text class="text-white font">上传物流信息</text>
			</view>
		</view>
	</view>
</template>

<script>
	import { mapState } from 'vuex';
	import Base64 from "base-64";
	import money from "@/components/tool/money.vue"
	import { accSub,accMul } from "@/static/js/GeneralUtil.js";
	import { mixins } from "./js/order.js"
	import {generalQueryBySQLSerialNumber,generalSave,generalQueryByTableName,getMemberPoint} from "@/api/generalBusiness.js"
	export default {
		components:{
			money
		},
		mixins:[mixins],
		data() {
			return {
				form:{
					Row_Status:'00'
				}
			}
		},
		onLoad(options) {
			this.getData(options.Refund_SerialNumber)
		},
		computed:{
			...mapState(['Open_ID','App_ID','BASE_IMG']),
			accSub(){
				return function(str1,str2){
					return accSub(str1,str2)
				}
			},
			accMul(){
				return function(str1,str2){
					return accMul(str1,str2)
				}
			},
			Row_Status(){
			    return function (str) {
					try{
						switch (str.charAt(1)) {
						    case "0":
						        return "待处理";
						    case "1":
						        return "已退款";
						    case "2":
						        return "已拒绝";
						    case "3":
						        return "待上传物流单号";
						    case "4":
						        return "退货中";
						    case "5":
						        return "已退货待处理退款";
						    case "6":
						        return "退货完成拒绝退款";
						    default:
						        return ""
						}
					}catch(e){
						return ""
					}
			        
			    }
			},
		},
		methods: {
			async getData(Refund_SerialNumber){
				const res = await generalQueryBySQLSerialNumber({
					SQLSerialNumber:"M_business_refund_detail",
					Condition:Base64.encode("%%,%%"),
					ExtensionCondition:Base64.encode(" AND business_refund_detail.Refund_SerialNumber='"+Refund_SerialNumber+"' ")
				})
				if(res.length == 1){
					this.form = res[0];
				}
			},
			handlesubmit(type){
				if(type=='logistics'){
					uni.showModal({
						title: "请填写物流信息",
						content: "",
						editable:true,
						success:async (data)=> {
							if (data.confirm) {
								if(!data.content){
									uni.showToast({
										title:'物流信息不能为空',
										icon:'none'
									})
									return
								}
								const {business_refund_detail,business_refund} =  await getMemberPoint({
									Data:JSON.stringify([{
										tableName: 'business_refund',
										Condition: Base64.encode(`Refund_SerialNumber='${this.form.Refund_SerialNumber}'`),
									},{
										tableName: 'business_refund_detail',
										Condition: Base64.encode(`Refund_SerialNumber='${this.form.Refund_SerialNumber}'`)
									}])
								})
								//明细可能存在多个，当组合支付时
								if(business_refund_detail.length >= 1 && business_refund.length == 1){
									let Row_Status = business_refund[0].Row_Status.charAt(0);
									business_refund[0].Row_Status = Row_Status + '4';
									business_refund_detail.forEach(item=>{
										item.Logistics_Number = data.content;
									})
									const res = await generalSave({
										Data:JSON.stringify({
											Modify:{business_refund_detail,business_refund}
										})
									})
									if(res.Status=='success'){
										this.getData(this.form.Refund_SerialNumber);
									}else{
										uni.showToast({
											title:'系统繁忙',
											icon:'none'
										})
									}
								}
							}
						},
					})
					
				}
			},
			
		}
	}
</script>

<style>

</style>